>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> %  Play some music in MatLab
>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>   %%
>>   %%   First we record some basic important frequencies
>>   %%
>> hearing = [20, 16000];    % frequency range that humans can hear
>> voice = [80, 3000];       % approx frequency range of human voice
>> Fs = 8192;                % default sound frequency in Matlab
>> CtoneFreq = 261.63;       % frequency of "middle C" note on piano ('Do')
>> DtoneFreq = 293.67;       % frequency of "D" on piano ('Re')
>> EtoneFreq = 329.63;       % frequency of "E" on piano ('Mi')
>> FtoneFreq = 349.23;       % frequency of "F" on piano ('Fa')
>> GtoneFreq = 392.00;       % frequency of "G" on piano ('Sol')
>> AtoneFreq = 440;          % frequency of "A" on piano ('La')
>> BtoneFreq = 493.88;       % frequency of "B" on piano ('Ti')
>>   %%
>>   %%  Now we create some short sound samples
>>   %%
>> nSeconds = 1;             % we'll make a bunch of 1 second samples
>> Cnote = sin(linspace(0, nSeconds*CtoneFreq*2*pi, nSeconds*Fs));
>> Dnote = sin(linspace(0, nSeconds*DtoneFreq*2*pi, nSeconds*Fs));
>> Enote = sin(linspace(0, nSeconds*EtoneFreq*2*pi, nSeconds*Fs));
>> Fnote = sin(linspace(0, nSeconds*FtoneFreq*2*pi, nSeconds*Fs));
>> Gnote = sin(linspace(0, nSeconds*GtoneFreq*2*pi, nSeconds*Fs));
>> Anote = sin(linspace(0, nSeconds*AtoneFreq*2*pi, nSeconds*Fs));
>> Bnote = sin(linspace(0, nSeconds*BtoneFreq*2*pi, nSeconds*Fs));
>> Cmajor = [Cnote, Dnote, Enote, Fnote, Gnote, Anote, Bnote];  
>> Cchord = Cnote + Enote + Gnote;
>>   %%
>>   %% Now we play them
>>   %%
>> sound(Cnote)              % 'Do'
>> sound(Dnote)              % 'Re'
>> sound(Enote)              % 'Mi'
>> sound(Cmajor)             % 'Do Re Mi Fa Sol La Ti'
>> sound(Cchord)             % Time to rock!
>>   %%
>>   %% Let's look at these
>>   %%  Raw soundwaves:
>>   %%
>> plot( Cnote(1:400) );     % soundwave for 'Do'
>> plot( Enote(1:400) );     % soundwave for 'Mi'
>> plot( Cchord(1:400) );    % soundwave for C-chord
>>   %%
>>   %%  Fourier coefficients recover frequency data:
>>   %%     fft is "Fast Fourier Transform"
>>   %%     to look at just amplitude (no phase shift) use "abs"
>>   %% 
>> plot( abs(fft(Cnote)) );  % Fourier transform has a spike at 'Do'
>> axis( [100,400,0,3500] ); % Zoom in to check spike at 261.63
>> plot( abs(fft(Cchord)) ); % Spikes at 'Do', 'Mi' and 'Sol'
>> axis( [200,500,0,4000] ); % Zoom in to check spikes at 261, 329, 392
>>   %%
>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> % Now we will make a 'Do' starting in the frequency domain
>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>   %% 
>>   %%   First create a vector of Fourier coeff of 'Do'
>>   %%
>> fftCnote = zeros(8192);    % start with a vector of all zeros
>> fftCnote(262+1) = 3000;    % put amplitude 3000 at frequency 262
>>                            %  Note: fftCnote(1) has freqency 0, etc
>> fftCnote(8192-262+1)=3000; % this coefficient is conjugate of 263
>>   %% 
>>   %%   Now take inverse fast fourier transform (ifft)
>>   %%
>> Cnote = ifft(fftCnote, 'symmetric'); 
>>   %%
>>   %%   This should sound like 'Do'.  Compare:
>>   %%
>> sound( Cnote(1:8192) )     % ifft sometimes puts junk at end
>> sound( cos( linspace(0, 261.63*2*pi, 8192) ), 8192 )   % 'Do'
>>   %%  
>>   %%   This should look like 'Do'.  Compare:
>>   %%    
>> plot( Cnote(1:8192) )
>> hold on
>> plot( cos( linspace(0, 261.63*2*pi, 8192) ) )
>> axis([0,500,-1,1]);
